package 命令模式;

/**
 * @author zzs
 * @ClassName LightCall.java
 * @Description 调用者来集合命令
 * @createTime 2022年05月16日 19:19:00
 */
public class BedRoomLoader {
    private Command[] openCommands;
    private Command[] closeCommands;
    private Command undoCommand;

    public BedRoomLoader() {
        openCommands = new Command[7];
        closeCommands = new Command[7];
        NoCommand noCommand = new NoCommand();
        for (int i = 0; i < 7; i++) {
            openCommands[i] = noCommand;
            closeCommands[i] = noCommand;
        }
        undoCommand = noCommand;
    }

    void setOpenCommands(int index, Command command) {
        openCommands[index] = command;
    }

    void setCloseCommands(int index, Command command) {
        closeCommands[index] = command;
    }

    void open(int index) {
        openCommands[index].execute();
        undoCommand = openCommands[index];
    }

    void close(int index) {
        closeCommands[index].execute();
        undoCommand = closeCommands[index];
    }

    void undo() {
        undoCommand.undo();
    }


}
